// pages/taskNumdetails/taskNumdetails.js
import api from '../../utils/api';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    taskNo: '',
    fpCode: '',
    deptName: '',
    userName: '',
    invId: '', //发票id
    contCode: '', //相关合同号
    proCode: '',
    conMoney: '',
    currMoney: '',
    saveButton: '', //是否显示保存按钮（是否能显示）

  },
  oncurrMoneyChange(e) {
    // console.log(parseFloat(e.detail.replace("¥","").replace(/\s*/g,'')))
    // console.log(e.detail.replace("¥","").replace(/\s*/g,''))
    this.data.currMoney = parseFloat(e.detail.replace("¥","").replace(/\s*/g,''));
    // this.setData({
    //   currMoney: e.detail
    // })
  },
  //清空
  qingkong() {
    this.setData({
      contCode: '',
      contId: ''
    })
    console.log(this.data.contCode, "contCode")
  },
  save() {
    let that = this
    api.newBillSave({
      method: 'post',
      data: {
        id: that.data.id,
        money: that.data.currMoney,
        contId: that.data.contId
      },
      success: function (res) {
        console.log(res.data.data, "newBillSave ")
        if (res.data.data == 1) {
          wx.showToast({
            title: '保存成功',
          })
          wx.navigateBack({
            delta: 1
          })
        }
      }
    })
  },
  //添加合同号
  addhetonghao() {
    wx.navigateTo({
      url: '../../pages/newbillfromTask/newbillfromTask?id= ' + this.data.id + '&invId=' + this.data.invId,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id,
      saveButton: options.saveButton
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this
    api.newBillDetails({
      data: {
        id: this.data.id,
      },
      success: function (res) {
        // console.log(res.data.data, "newBillDetails ")
        if (res.data.code == 200) {
          that.setData({
            fpCode: res.data.data.fpCode,
            deptName: res.data.data.deptName,
            userName: res.data.data.userName,
            code: res.data.data.code,
            invid: res.data.data.id,
            taskNo: res.data.data.taskCode,
            proCode: res.data.data.taskName,
            conMoney: res.data.data.contTaskMoney,
            currMoney: res.data.data.money,
            invId: res.data.data.invId,
            contCode: res.data.data.contCode,
            contId: res.data.data.contId
          })
          // console.log(res.data.data.contId)
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})